<?php
namespace Modules\Frontend;

use Phalcon\DiInterface;

class Module implements \Phalcon\Mvc\ModuleDefinitionInterface {
    public function registerAutoloaders(DiInterface $di = null) {
        (new \Phalcon\Loader()) -> registerNamespaces([
			'Gregwar\\Captcha' => BASE_PATH . 'vendor/gregwar/captcha/src/Gregwar/Captcha',

			'Assert'    => BASE_PATH . 'vendor/beberlei/assert/lib/Assert/',
			'Base64Url' => BASE_PATH . 'vendor/spomky-labs/base64url/src/',
			'Jose'      => BASE_PATH . 'vendor/spomky-labs/jose/src/',

            'Components' => SRC_PATH.DS.'components'.DS,

            __NAMESPACE__ . '\\Controllers' => __DIR__.DS.'controllers'.DS,
        ]) -> register();
    }


    public function registerServices(DiInterface $di) {
		$di -> set('dispatcher', function() {
			$dispatcher = new \Phalcon\Mvc\Dispatcher();
			$dispatcher -> setDefaultNamespace(__NAMESPACE__ . '\\Controllers');
			return $dispatcher;
		});

		$di -> set('account', function() {
			return \Components\Account\Factory::load([
				'adapter' => 'User'
			]);
		}, false);

		$di -> set('trade', function() {
			return \Components\Trade\Factory::load([
				'adapter' => 'First'
			]);
		}, false);

		$di -> set('tradeSecond', function() {
			return \Components\Trade\Factory::load([
				'adapter' => 'Second'
			]);
		}, false);

		$di -> set('SMS', function() {
			return \Components\SMS\Factory::load([
				'adapter' => 'First'
			]);
		});

		$di -> set('products', function() {
			return \Components\Products\Factory::load([
				'adapter' => 'First'
			]);
		}, false);

        $di -> set('view', function () {
			return (new \Phalcon\Mvc\View()) -> disable();
        });

		$di -> set('notice', function() {
			return \Components\Notice\Factory::load([
				'adapter' => 'First'
			]);
		});

		$di -> set('swipe', function() {
			return \Components\Swipe\Factory::load([
				'adapter' => 'First'
			]);
		});

		$di -> set('parameter', function() {
			return \Components\Parameter\Factory::load([
				'adapter' => 'First'
			]);
		});
    }
}